Option Strict On
Option Explicit On 

Public Class UUser
    Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnPassword As System.Windows.Forms.Button
    Friend WithEvents txtFullName As System.Windows.Forms.TextBox
    Friend WithEvents txtCompanyId As System.Windows.Forms.TextBox
    Friend WithEvents lblCompanyId As System.Windows.Forms.Label
    Friend WithEvents lblFullName As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(UUser))
        Me.btnPassword = New System.Windows.Forms.Button
        Me.txtFullName = New System.Windows.Forms.TextBox
        Me.lblFullName = New System.Windows.Forms.Label
        Me.txtCompanyId = New System.Windows.Forms.TextBox
        Me.lblCompanyId = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'btnPassword
        '
        Me.btnPassword.Cursor = System.Windows.Forms.Cursors.Default
        resources.ApplyResources(Me.btnPassword, "btnPassword")
        Me.btnPassword.Name = "btnPassword"
        '
        'txtFullName
        '
        resources.ApplyResources(Me.txtFullName, "txtFullName")
        Me.txtFullName.Name = "txtFullName"
        '
        'lblFullName
        '
        resources.ApplyResources(Me.lblFullName, "lblFullName")
        Me.lblFullName.Name = "lblFullName"
        '
        'txtCompanyId
        '
        resources.ApplyResources(Me.txtCompanyId, "txtCompanyId")
        Me.txtCompanyId.Name = "txtCompanyId"
        '
        'lblCompanyId
        '
        resources.ApplyResources(Me.lblCompanyId, "lblCompanyId")
        Me.lblCompanyId.Name = "lblCompanyId"
        '
        'UUser
        '
        Me.Controls.Add(Me.txtCompanyId)
        Me.Controls.Add(Me.lblCompanyId)
        Me.Controls.Add(Me.btnPassword)
        Me.Controls.Add(Me.txtFullName)
        Me.Controls.Add(Me.lblFullName)
        Me.Name = "UUser"
        resources.ApplyResources(Me, "$this")
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

    Private pwd As String

    Private mOwn As Boolean

    Public Event ValueChanged As EventHandler

    Private Sub UCommand_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler txtFullName.TextChanged, AddressOf OnValueChanged
        AddHandler txtCompanyId.TextChanged, AddressOf OnValueChanged
    End Sub
    Private Sub btnPassword_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPassword.Click
        Dim frm As New Avand.Password(mOwn, pwd)
        If frm.ShowDialog(Me) = DialogResult.OK Then
            pwd = frm.Password
            OnValueChanged(Me, New EventArgs)
        End If
        frm.Close() : frm = Nothing
    End Sub

    Protected Sub OnValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        RaiseEvent ValueChanged(Me, New EventArgs)
    End Sub

    Public Property Own() As Boolean
        Get
            Return mOwn
        End Get
        Set(ByVal Value As Boolean)
            mOwn = Value
        End Set
    End Property

    Public Sub Read(ByVal user As Model10.User)
        txtFullName.Text = user.FullName
        txtCompanyId.Text = user.CompanyId.ToString
        pwd = user.Password
    End Sub
    Public Sub Write(ByVal user As Model10.User)
        user.FullName = txtFullName.Text
        user.CompanyId = CInt(txtCompanyId.Text)
        user.Password = pwd
    End Sub
End Class